using FireStarterModeller.BO;
using FireStarterModeller.Test.BO;
using FireStarterModeller.UI;
using Habanero.Faces.Base;
using Habanero.Faces.Win;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI
{
    [TestFixture]
    public class TestProjectAssemblyInfoControl 
    {
        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }


        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();

        }


        private static IControlFactory GetControlFactory()
        {
            return GlobalUIRegistry.ControlFactory;
        }
        [Ignore("Changing how this works")] 
        [Test]
        public void TestLayout()
        {
            //---------------Execute Test ----------------------
            ProjectAssemblyInfoControl projectAssemblyInfoControl = new ProjectAssemblyInfoControl(GetControlFactory());

            //---------------Test Result -----------------------
            Assert.AreEqual(1, projectAssemblyInfoControl.Controls.Count);
            IPanelInfo panelBuilderInfo = projectAssemblyInfoControl.BusObjectPanelBuilderInfo;
            Assert.IsNotNull(panelBuilderInfo);
            PanelInfo.FieldInfoCollection mappers = panelBuilderInfo.FieldInfos;
            Assert.IsNotNull(mappers);
            Assert.AreEqual(1, mappers.Count);
            Assert.IsInstanceOf(typeof(ITextBox), mappers["Name"].ControlMapper.Control);
        }

        [Test]
        public void TestBusinessObjectIsSameAsOneInPanelInfo()
        {
            //---------------Set up test pack-------------------
            ProjectAssemblyInfoControl projectAssemblyInfoControl = new ProjectAssemblyInfoControl(GetControlFactory());
            //---------------Assert Precondition----------------
            Assert.AreEqual(projectAssemblyInfoControl.BusinessObject, projectAssemblyInfoControl.BusObjectPanelBuilderInfo.BusinessObject);
            //---------------Execute Test ----------------------
            DMAssembly newBO = new DMAssembly();
            projectAssemblyInfoControl.BusinessObject = newBO;
            //---------------Test Result -----------------------
            Assert.AreEqual(newBO, projectAssemblyInfoControl.BusinessObject);
            Assert.AreEqual(newBO, projectAssemblyInfoControl.BusObjectPanelBuilderInfo.BusinessObject);
        }

        [Ignore("Changing the way this behaves")]
        [Test]
        public void Test_DisplayErrors()
        {
            //---------------Set up test pack-------------------
            ProjectAssemblyInfoControl projectAssemblyInfoControl = new ProjectAssemblyInfoControl(GetControlFactory());
            DMAssembly newBO = new DMAssembly();
            projectAssemblyInfoControl.BusinessObject = newBO;
            PanelInfo.FieldInfo fieldInfo = projectAssemblyInfoControl.BusObjectPanelBuilderInfo.FieldInfos["Name"];
            //---------------Assert Precondition----------------
            Assert.IsFalse(fieldInfo.ControlMapper.ErrorProvider.GetError(fieldInfo.InputControl).Length > 0);

            //---------------Execute Test ----------------------
            projectAssemblyInfoControl.DisplayErrors();

            //---------------Test Result -----------------------
            Assert.IsTrue(fieldInfo.ControlMapper.ErrorProvider.GetError(fieldInfo.InputControl).Length > 0);
        }

        [Test]
        public void Test_ClearErrors()
        {
            //---------------Set up test pack-------------------
            ProjectAssemblyInfoControl projectAssemblyInfoControl = new ProjectAssemblyInfoControl(GetControlFactory());
            DMAssembly newBO = new DMAssembly();
            projectAssemblyInfoControl.BusinessObject = newBO;
            PanelInfo.FieldInfo fieldInfo = projectAssemblyInfoControl.BusObjectPanelBuilderInfo.FieldInfos["Name"];
            projectAssemblyInfoControl.DisplayErrors();

            //---------------Assert Precondition----------------
            Assert.IsTrue(fieldInfo.ControlMapper.ErrorProvider.GetError(fieldInfo.InputControl).Length > 0);

            //---------------Execute Test ----------------------
            projectAssemblyInfoControl.ClearErrors();

            //---------------Test Result -----------------------
            Assert.IsFalse(fieldInfo.ControlMapper.ErrorProvider.GetError(fieldInfo.InputControl).Length > 0);
        }
        
    }


}